//
//  LZLoginButtonView.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/24.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZLoginButtonView.h"
#import "Masonry.h"
#import "BlocksKit+UIKit.h"

@implementation LZLoginButtonView

- (instancetype)initWithPage:(LZLOGINBUTTONTYPE_PAGE)page {
    self = [super init];
    if (self) {
        self.page = page;
        [self setup];
    }
    return self;
}

- (void)setup {
    
    GET_SCREEN_SCALE(scale);
    
    if (self.page == LZLOGINBUTTONTYPE_PAGE_LOGIN) {
        [self addSubview:self.loginOrRegisterButton];
        [self addSubview:self.registerButton];
        
        
        [self.loginOrRegisterButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(0);
            make.height.mas_equalTo(55.0*scale);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(self.registerButton.mas_top);
        }];
        
        [self.registerButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(55.0*scale);
        }];
    }
    else if (self.page == LZLOGINBUTTONTYPE_PAGE_REGISTER) {
        [self addSubview:self.registerButton];
        [self addSubview:self.registerByTypeButton];
        
        
        [self.registerButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(0);
            make.height.mas_equalTo(55.0*scale);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(self.registerByTypeButton.mas_top);
        }];
        
        [self.registerByTypeButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(55.0*scale);
        }];
    }
}

#pragma mark - setter/getter

- (UIButton *)loginOrRegisterButton {
    
    if (_loginOrRegisterButton == nil) {
        
        WS(weakSelf);
        GET_SCREEN_SCALE(scale);
        
        _loginOrRegisterButton = [[UIButton alloc] init];
        _loginOrRegisterButton.backgroundColor  = UIColorFromRGB(0xf2871c, 1);
        _loginOrRegisterButton.tag              = LZLOGINBUTTONTYPE_TAG_LOGINNOW;
        _loginOrRegisterButton.titleLabel.font  = [UIFont systemFontOfSize:17.0*scale];
        [_loginOrRegisterButton setTitle:LZLocalizedString(@"login_loginnow", @"") forState:UIControlStateNormal];
        [_loginOrRegisterButton setTitleColor:UIColorFromRGB(0xffffff, 1) forState:UIControlStateNormal];
        
        [_loginOrRegisterButton bk_addEventHandler:^(id  _Nonnull sender) {
            if (weakSelf.buttonActionBlock) {
                weakSelf.buttonActionBlock(LZLOGINBUTTONTYPE_TAG_LOGINNOW);
            }
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _loginOrRegisterButton;
}

- (UIButton *)registerButton {
    
    if (_registerButton == nil) {
        
        WS(weakSelf);
        GET_SCREEN_SCALE(scale);
        
        _registerButton = [[UIButton alloc] init];
        _registerButton.backgroundColor   = UIColorFromRGB(0xe47201, 1);
        _registerButton.tag               = LZLOGINBUTTONTYPE_TAG_REGISTER;
        _registerButton.titleLabel.font   = [UIFont systemFontOfSize:17.0*scale];
        [_registerButton setTitle:LZLocalizedString(@"login_register", @"") forState:UIControlStateNormal];
        [_registerButton setTitleColor:UIColorFromRGB(0xffffff, 1) forState:UIControlStateNormal];
        
        [_registerButton bk_addEventHandler:^(id  _Nonnull sender) {
            if (weakSelf.buttonActionBlock) {
                weakSelf.buttonActionBlock(LZLOGINBUTTONTYPE_TAG_REGISTER);
            }
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _registerButton;
}

- (UIButton *)registerByTypeButton {
    
    if (_registerByTypeButton == nil) {
        
        WS(weakSelf);
        GET_SCREEN_SCALE(scale);
        
        _registerByTypeButton = [[UIButton alloc] init];
        _registerByTypeButton.tag               = LZLOGINBUTTONTYPE_TAG_REGISTERBYTYPE;
        _registerByTypeButton.titleLabel.font   = [UIFont systemFontOfSize:17.0*scale];
        [_registerByTypeButton setTitleColor:UIColorFromRGB(0xff9933, 1) forState:UIControlStateNormal];
        
        [_registerByTypeButton bk_addEventHandler:^(id  _Nonnull sender) {
            if (weakSelf.buttonActionBlock) {
                weakSelf.buttonActionBlock(LZLOGINBUTTONTYPE_TAG_REGISTERBYTYPE);
            }
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _registerByTypeButton;
}

@end
